public class test627 {
    public static boolean isPrime(int num) {
        if (num <= 1) return false;
        if (num == 2) return true;
        if (num % 2 == 0) return false;
        for (int i = 3; i <= Math.sqrt(num); i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
    public static int reverse(int num) {
        int reversed = 0;
        while (num > 0) {
            reversed = reversed * 10 + num % 10;
            num /= 10;
        }
        return reversed;
    }
    public static void main(String[] args) {
        int count = 0;
        int num = 2;
        while (count < 100) {
            int reversedNum = reverse(num);
            if (num != reversedNum && isPrime(num) && isPrime(reversedNum)) {
                System.out.print(num + " ");
                count++;
                if (count % 10 == 0) System.out.println(); 
            }
            num++;
        }
    }
}

